package com.xtgg.util;

import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.umeng.message.UmengRegistrar;
import com.xtgg.main.MainPageActivity;
import com.xtgg.sys.DemoApp;

public class MgqRestClient {
	public final static String TAG = "MgqRestClient";
	private static final String BASE_URL = "";

	private static AsyncHttpClient client = new AsyncHttpClient();

	public static void get(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		if (params != null) {
			TLog.i(TAG, "get url:" + url + "    " + params.toString());
		}

		params.put("userid", PreferencesUtils.getString(DemoApp.getContext(), "userid"));
		params.put("device_token", UmengRegistrar.getRegistrationId(DemoApp.getContext()));
		client.setTimeout(30000);
		client.get(getAbsoluteUrl(url), params, responseHandler);
	}

	public static void post(String url, RequestParams params,
			AsyncHttpResponseHandler responseHandler) {
		if (params != null) {
			TLog.i(TAG, "post url:" + url + "    " + params.toString());
		}

		params.put("userid", PreferencesUtils.getString(DemoApp.getContext(), "userid"));
		params.put("device_token", UmengRegistrar.getRegistrationId(DemoApp.getContext()));
		client.setTimeout(60000);
		client.post(getAbsoluteUrl(url), params, responseHandler);
	}

	private static String getAbsoluteUrl(String relativeUrl) {
		return relativeUrl;
	}
}
